/**
* Group: Y1
* This is the Ship object that will hold position and velocity values plus health
* Usage: Ship(positionX, positionY, Team Number);
* @author Venkat Patnala
*/
package lightspeed.Backend;

public class Ship {
	
	private float vX, vY, x, y, a;
	private int angle; //rotation angle from 0 to 35
	public boolean dead;
	private short dead_timer;
	private static short DEAD_TIME = 60;
	private static short BOUNDX = 3000, BOUNDY = 3000;
	/**
	* The team holds the number of the team to which the ship belongs to	
	*/
	public short team;
	/**
	* The dmamage is an integer that keeps track of the damadge of the ship.
	*/
	public int damage;
	public static float MAX_DAMAGE = 3;
	//public float vVector;
	/**
	* MAX_VELOCITY is the maximum velocity that can be obtained by a ship (30)
	*/
	public static int MAX_VELOCITY = 35;
	/**
	* Constructor: creates a ship instance.
	*  Sets default to all the ship's characterisitcs such as damadge, angle, velocity vecoter, x&y coordinates, team, and x&y velocity.	
	*	@param X x cordinate of the ship
	*	@param Y y cordinate of the ship
	*	@param t damadge of the ship
	*/
	public Ship(float X, float Y, short t) {
		team = t;
		this.x = X;
		this.y = Y;
		vX = 0;
		vY = 0;
		damage = 0;
		dead = false;
		dead_timer = DEAD_TIME;
		
		angle = 0;
		//vVector = 0;
	}
	/**
	*	Reset method sets default values to all the characteristics of the ship.
	*	Sets a random x&y coordinate, and a 0 velcoty and damage.
	*	This method will be called when a ship respawns.
	*/
	public void reset(){
		float modX = (float)Math.random()*100;
		float modY = (float)Math.random()*100;
		if((((int)(Math.random()*2)) % 2) == 0)
			modX*=-1;
		if((((int)(Math.random()*2)) % 2) == 0)
			modY*=-1;
		if(((int)(team) & 1) == 0) //blue team
		{
			this.x = (float) (GameManager.flagBlue.startX + modX);
			this.y = (float) (GameManager.flagBlue.startY + modY);
		}
		else //red team
		{
			this.x = (float) (GameManager.flagRed.startX + modX);
			this.y = (float) (GameManager.flagRed.startY + modY);
		}
		vX = 0;
		vY = 0;
		damage = 0;
		dead = false;
		dead_timer = DEAD_TIME;
	}
	/**
	* Gets the x coordinate of the ship	
	* @return x int value of x coordinate
	*/
	public int getX() {
		return (int)x;
	}
	/**
	* Gets the y coordinate of the ship	
	* @return y int value of y coordinate
	*/
	public int getY() {
		return (int)y;
	}
	/**
	* Gets the x velocity of the ship	
	* @return vX int value of x velocity
	*/
	public float getVx() {
		return vX;
	}
	/**
	* Gets the y velocity of the ship	
	* @return vy int value of y velocity 
	*/
	public float getVy() {
		return vY;
	}
	/**
	* Gets the angle of the ship
	* @return angle int value of ship's angle
	*/
	public int getAngle()
	{
		return angle;
	}
	/**
	* Sets the angle of the ship
	* @param ang int value of ship's angle to be set
	*/
	public void setAngle(int ang)
	{
		angle = ang;
	}
	/**
	* Increments damadge to the ship
	* @param inc the amount of damadge to increment to the ship.
	* @return boolean to indicate wheather damadge was incremented
	*/	
	public boolean incrementDamage(int inc) {
		if(damage!=MAX_DAMAGE) {
			damage += inc;
			return true;
		}else {
			dead = true;
			return false;
		}
	}
	/**
	* Gets the angle of the ship
	* @return damage int value that represents damage done to the ship.
	*/
	
	public int getDamage(){
		return (int)damage;
	}
	/**
	* Sets the velocity of the ship
	* @param vX the x-velcoity to set
	* @param vY the y-velcoity to set
	*/
	public void setVelocity(float vX, float vY){
		this.vX = vX;
		this.vY = vY;
	}
	/**
	* Updates the latest position of the ship 
	*/
	public void updatePosition() {
		x += vX;
		y += vY;
		if (x<0){
			x = 0;
			vX = -vX*(float).3;
			//vVector = vY;
		}
		if (x>BOUNDX){
			x = BOUNDX;
			vX = -vX*(float).3;
			//vVector = vY;
		}
		if (y<0){
			y = 0;
			vY = -vY*(float).3;
			//vVector = vX;
		}
		if (y>BOUNDY){
			y = BOUNDY;
			vY = -vY*(float).3;
			//vVector = vX;
		}
		System.out.println(x+","+y+":"+vX+","+vY+":"+angle+":"+damage);
		
		if (dead)
		{
			vX*=(float).95;
			vY*=(float).95;
			if (dead_timer != 0)
				--dead_timer;
			else {
				reset();
			}

		}
	}
	
}